home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_441 / dme / src / mods.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  178 lines

  1.  
  2. /*
  3.  *  KTS.C
  4.  *
  5.  *  Additional DME commands written by Kevin T. Seghetti fixed up and
  6.  *  incorporated by Matt Dillon 17 April 1988.
  7.  */
  8.  
  9. #include "defs.h"
  10. #include <intuition/intuitionbase.h>
  11.  
  12. Prototype void PMAdd (void);
  13. Prototype void PMRem (void);
  14. Prototype void PMKill (struct _ED *);
  15. Prototype int do_pushmark (void);
  16. Prototype void do_popmark (void);
  17. Prototype void do_swapmark (void);
  18. Prototype void do_purgemark (void);
  19. Prototype void do_ping (void);
  20. Prototype void do_pong (void);
  21. Prototype void do_undo (void);
  22.  
  23. #define BLOCKDEPTH  5
  24. #define PINGDEPTH   10
  25.  
  26. static long BSstack[BLOCKDEPTH];
  27. static long BEstack[BLOCKDEPTH];
  28. static ED   *Bp[BLOCKDEPTH];
  29. static int  CurrDepth = 0;
  30.  
  31. static long PingLine[PINGDEPTH];
  32. static long PingCol[PINGDEPTH];
  33. static ED   *PingWin[PINGDEPTH];
  34.  
  35. void
  36. PMAdd()
  37. {
  38. }
  39.  
  40. void
  41. PMRem()
  42. {
  43. }
  44.  
  45. void
  46. PMKill(ep)
  47. ED *ep;
  48. {
  49.     short i, j;
  50.  
  51.     for (i = 0; i < PINGDEPTH; ++i) {       /*  remove ping-pong marks  */
  52.     if (PingWin[i] == ep)
  53.         PingWin[i] = NULL;
  54.     }
  55.     for (i = j = 0; i < CurrDepth; ++i) {   /*  remove block marks      */
  56.     Bp[j] = Bp[i];
  57.     if (Bp[i] != ep)
  58.         ++j;
  59.     }
  60.     CurrDepth = j;
  61. }
  62.  
  63. do_pushmark()
  64. {
  65.     text_sync();
  66.     if (blockok()) {
  67.     if (CurrDepth == BLOCKDEPTH) {
  68.         title("pushmark: stack limit reached");
  69.         return(-1);
  70.     }
  71.     BSstack[CurrDepth] = BSline;
  72.     BEstack[CurrDepth] = BEline;
  73.     Bp[CurrDepth] = BEp;
  74.  
  75.     ++CurrDepth;
  76.     text_redrawblock(0);
  77.     }
  78.     return(0);
  79. }
  80.  
  81. void
  82. do_popmark()
  83. {
  84.     text_sync();
  85.  
  86.     if (!CurrDepth) {           /*  no error message on purpose */
  87.     text_redrawblock(0);    /*  remove any existing block   */
  88.     return;
  89.     }
  90.     text_redrawblock(0);
  91.     --CurrDepth;
  92.     BSline = BSstack[CurrDepth];
  93.     BEline = BEstack[CurrDepth];
  94.     BEp = Bp[CurrDepth];
  95.     if (BEp == NULL || BEline >= BEp->Lines) {
  96.     BEp = NULL;
  97.     BSline = BEline = -1;
  98.     } else
  99.     text_redrawblock(1);
  100. }
  101.  
  102. void
  103. do_swapmark()
  104. {
  105.     short i;
  106.     long *ptmp;
  107.     long tmp;
  108.  
  109.     if (do_pushmark() < 0)
  110.     return;
  111.     i = CurrDepth - 2;
  112.     if (i >= 0) {
  113.     ptmp = PingLine + i;
  114.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  115.     ptmp = PingCol + i;
  116.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  117.     ptmp = (long *)PingWin + i;
  118.     tmp = ptmp[0]; ptmp[0] = ptmp[1]; ptmp[1] = tmp;
  119.     }
  120.     do_popmark();
  121. }
  122.  
  123. void
  124. do_purgemark()
  125. {
  126.     CurrDepth = 0;
  127. }
  128.  
  129. void
  130. do_ping()
  131. {
  132.     uword num = atoi(av[1]);
  133.  
  134.     if (num >= PINGDEPTH) {
  135.     title("ping: out of range");
  136.     return;
  137.     }
  138.     PingLine[num]= Ep->Line;
  139.     PingCol[num] = Ep->Column;
  140.     PingWin[num] = Ep;
  141.     title("Line marked");
  142. }
  143.  
  144. void
  145. do_pong()
  146. {
  147.     uword num = atoi(av[1]);
  148.     extern IBASE *IntuitionBase;
  149.  
  150.     text_sync();
  151.     if (num < 0 || num >= PINGDEPTH || !PingWin[num]) {
  152.     title("pong: range error or nothing marked");
  153.     return;
  154.     }
  155.     text_cursor(1);
  156.     text_switch(PingWin[num]->Win);
  157.     text_cursor(0);
  158.  
  159.     if (IntuitionBase->ActiveWindow != Ep->Win) {
  160.     WindowToFront(Ep->Win);
  161.     ActivateWindow(Ep->Win);
  162.     }
  163.     if ((Ep->Line = PingLine[num]) >= Ep->Lines) {
  164.     PingLine[num] = Ep->Line = Ep->Lines - 1;
  165.     }
  166.     Ep->Column = PingCol[num];
  167.     text_load();
  168.     text_sync();
  169. }
  170.  
  171. void
  172. do_undo()
  173. {
  174.     text_load();
  175.     text_redisplaycurrline();
  176. }
  177.  
  178.